"""日志页面"""
from time import sleep
from page.base_page import BasePage
from selenium.webdriver.common.by import By
from page.index_page import IndexPage
from page.login_page import LoginPage

class LogPage(BasePage):
    url='/crm5/index.php?m=log'
    #选择日志框定位器
    btn_select_locator = (By.NAME, "log_id[]")
    #删除定位器
    btn_delete_locator = (By.ID, "delete")
    #搜索字段下拉框定位器
    field_locator = (By.ID, "field")
    #搜索字段输入框定位器
    search_text_locator = (By.ID, "search")
    #搜索按钮定位器
    btn_search_locator = (By.CSS_SELECTOR, "#searchForm > ul > li:nth-child(4) > button")
    #添加日志定位器
    add_log_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(2) > div > a")
    #添加成功文本定位器
    add_success_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    #添加错误文本定位器
    add_error_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-error")
    #每页显示条数定位器
    exist_num=(By.CSS_SELECTOR,"#form1 > table > tfoot > tr > td > div > div:nth-child(1)")
    #搜素后出现内容的第一个定位器
    searched_locator=(By.XPATH,"/html/body/div[5]/div[2]/div[3]/form/table/tbody/tr[1]/td[3]/a")

    def btn_select(self):
        """返回日志勾选框的元素对象"""
        return self.driver.find_elements(*self.btn_select_locator)
    def btn_delete(self):
        """点击删除按钮"""
        self.driver.find_element(*self.btn_delete_locator).click()
    def click_field(self):
        """返回搜索下拉框的元素对象"""
        return self.driver.find_element(*self.field_locator)
    def input_search_text(self, text):
        """输入搜索关键字文本"""
        self.driver.find_element(*self.search_text_locator).send_keys(text)
    def click_btn(self):
        """点击搜索按钮"""
        self.driver.find_element(*self.btn_search_locator).click()
    def click_add_log(self):
        """点击添加日志按钮"""
        self.driver.find_element(*self.add_log_locator).click()
    def success_tip_text(self):
        """返回添加成功后的文本信息"""
        return self.driver.find_element(*self.add_success_locator).text
    def error_tip_text(self):
        """返回添加失败的文本信息"""
        return self.driver.find_element(*self.add_error_locator).text
    def exist_num_text(self):
        """返回页面现有条数内容的文本信息"""
        return self.driver.find_element(*self.exist_num).text
    def search_text(self):
        """返回搜索后的第一条内容的文本信息"""
        return self.driver.find_element(*self.search_text_locator).text

    def log_page(self, username, password):
        """ 封装“登录后进入日志页面”的公共流程"""
       #实例化登录页面
        lp=LoginPage(self.driver)
        # 复用登录方法
        lp.login(username, password)
        #实例化主页页面
        ip = IndexPage(self.driver)
        #点击更多按钮
        ip.click_btn_more()
        sleep(1)
        #点击日志按钮
        ip.click_log()
        sleep(1)

